package com.platform.qujia.enums;

import com.platform.qujia.utils.StringUtils;

import java.util.HashMap;

/**
 * @date 2023/9/20
 */
public enum CardRecordType {

    MANUAL_ADD("imp","手动充值"),
    MANUAL_SUB("msub","手动扣减"),
    WX_RECHARGE("wx","微信充值"),
    CONSUME("","电子卡支付"),
    REFUND("ref","充值退款"),
    POS_REFUND("pref","pos充值退款"),
    WX_REFUND("wxref","微信充值退款"),
    CONSUME_REFUND("csRef","消费退款"),
    CONSUME_PRESENT("cs_pt","消费赠送"),
    POS_PRESENT("posPr","POS赠送"),
    POS_RECHARGE("pos","移动支付"),
    ;

    private final String key;
    private final String name;

    CardRecordType(String key, String name) {
        this.key = key;
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public String getName() {
        return name;
    }

    private static HashMap<String, CardRecordType> keyMap;

    public static CardRecordType getByKey(String key){
        if (keyMap == null) {
            HashMap<String, CardRecordType> map = new HashMap<>();
            for (CardRecordType value : CardRecordType.values()) {
                map.put(value.getKey(),value);
            }
            keyMap = map;
        }
        return keyMap.get(key);
    }

    public static CardRecordType getByKey(String key,CardRecordType recordType){
        CardRecordType type = getByKey(key);
        return type == null ? recordType : type;
    }

}
